﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static AlarmClockConsoleApp.Program;

namespace AlarmClockConsoleApp
{
    /// <summary>
    /// 闹钟实体类
    /// </summary>
    public class AlarmClock
    {
        private int Hour = 0;
        private int Minute = 0;
        private int Second = 0;

        public event BellEventHandler BellEvent;

        public event TickEventHandler TickEvent;

        public void StartBell()
        {
            while (!(DateTime.Now.Hour == Hour && DateTime.Now.Minute == Minute && DateTime.Now.Second == Second))
            {
                BellEventArgs bellEventArgsTick = new BellEventArgs(Hour, Minute, Second, "嘀嗒");
                TickEvent(this, bellEventArgsTick);
                Thread.Sleep(1000);
            }
            BellEventArgs bellEventArgs = new BellEventArgs(Hour, Minute, Second, "起床了");
            BellEvent(this, bellEventArgs);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_h"></param>
        /// <param name="_m"></param>
        /// <param name="_s"></param>
        /// <returns></returns>
        public bool SetBellTime(int _h, int _m, int _s)
        {
            if (_h > 24)
            {
                return false;
            }
            if (_m > 60)
            {
                return false;
            }
            if (_s > 60)
            {
                return false;
            }
            Hour = _h;
            Minute = _m;
            Second = _s;
            return true;
        }
    }
}
